import { LocalstorageDataManage } from './../../../common/localstoreage/localstoreageDataManage';
import { Component, OnInit } from '@angular/core';
import * as R from "ramda";

@Component({
    styleUrls: ['./deliverySetup.component.scss'],
    templateUrl: './deliverySetup.component.html'
})


export class DeliveryComponent implements OnInit {
    ngOnInit() {
        function changeOrderConfig(config) {
            const orderConfig = LocalstorageDataManage.current.getOrderConfig();
            Object.keys(config).forEach(v=>orderConfig[v] = config[v])
            LocalstorageDataManage.current.setOrderConfig(orderConfig)
        }
        this.templateOptions.find(option => option.name == "orderConfigIsOpenTimeoutSound").onChange = (sender: {
            checked: boolean
        }) => {
            changeOrderConfig({ isOpenTimeoutSound: sender.checked })
        }
        this.templateOptions.find(option => option.name == "orderConfigTimeoutTiming").onChange = (sender: {
            timing: number
        }) => {
            changeOrderConfig({ timeoutTiming: sender.timing })
        }
    }

    templateOptions = [{
        name: "orderConfigTimeoutTiming",
        type: "count",
        "title": "超时订单时长",
        "description": "超过该时长仍未出品的订单会以红色标记",
        timing: LocalstorageDataManage.current.getOrderConfig().timeoutTiming,
        min: 0,
        max: 100,
        increaseOperation: function () {
            const timing = this.timing;
            this.timing += 1;
            if (!this.check()) {
                this.timing = timing;
                return;
            }
            this.onChange(this);
        },
        decreaseOperation: function () {
            const timing = this.timing;
            this.timing -= 1;
            if (!this.check()) {
                this.timing = timing;
                return;
            }
            this.onChange(this);
        },
        check() {
            return this.timing >= this.min && (this.timing <= this.max);
        },
        onChange: (sender: { timing: number }) => { }
    },
    {
        name: "orderConfigIsOpenTimeoutSound",
        "title": "超时提示音",
        "description": "",
        type: "switch",
        timing: LocalstorageDataManage.current.getOrderConfig().timeoutTiming,
        checked: LocalstorageDataManage.current.getOrderConfig().isOpenTimeoutSound,
        operation(option) {
            this.checked = !this.checked;
            this.onChange(this);
        },
        onChange: (sender: { checked: boolean }) => { }
    }]
}